import Vue from 'vue'
import VueRouter from 'vue-router'
import {jtRouter} from '../utils/data'
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

// const routes = [
//   {
//     path: '/',
//     name: 'home',
//     component: HomeView
//   },
//   {
//     path: '/about',
//     name: 'about',
//     // route level code-splitting
//     // this generates a separate chunk (about.[hash].js) for this route
//     // which is lazy-loaded when the route is visited.
//     component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
//   }
// ]

// 报错Uncaught (in promise) NavigationDuplicated: Avoided redundant navigation to current location: "/person".
// 参考http://events.jianshu.io/p/b0b5aee24191
// 获取原型对象上的push函数
const originalPush = VueRouter.prototype.push
// 修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const routesJt = [
  {
    path: '/',
    name: 'home',
    component: HomeView,
    redirect:'LeftFind',
    children:[
      {
        path: '/person',
        name: 'person',
        component: ()=>import('../components/person.vue'),
        children:[
          {
            path: '/found',
            name: 'personFound',
            component: ()=>import('../components/person/found.vue'),
          },
          {
            path: '/sc',
            name: 'personSc',
            component: ()=>import('../components/person/sc.vue'),
          },
          {
            path: '/music',
            name: 'personMusic',
            component: ()=>import('../components/person/music.vue'),
          }
        ]
      },
          {
            path: '/edit',
            name: 'edit',
            component: ()=>import('../components/person/edit.vue'),
          }
    ]
  },
 

]
  
const routes = routesJt
const router = new VueRouter({
  routes,
  mode: 'history'//设置为hash模式
})
jtRouter.forEach(items => {
  router.addRoute('home',items)
// console.log(items)
});

export default router
